package com.company.app.listener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;

import com.company.app.spring.ContextHolder;

public class ApplicationListener implements ServletRequestListener {

	@Override
	public void requestDestroyed(ServletRequestEvent sre) {
	
	}

	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		//sre.getServletRequest().get
		String path = "http://" + sre.getServletRequest().getServerName() + ":" +  sre.getServletRequest().getServerPort() + sre.getServletContext().getContextPath() ;
		if (sre.getServletRequest().getAttribute("AppHostName")==null){
			sre.getServletRequest().setAttribute("AppHostName", path);
		}
		if (sre.getServletRequest().getAttribute("JqWidgetsVersion")==null){
			sre.getServletRequest().setAttribute("JqWidgetsVersion", ContextHolder.getProperty("app.jqwidgets.version"));
		}
		
		if (sre.getServletRequest().getAttribute("RestContextPath")==null){
			sre.getServletRequest().setAttribute("RestContextPath", ContextHolder.getProperty("app.backend.restContextPath"));
		}
		
		if (sre.getServletRequest().getAttribute("BackendHost")==null){
			sre.getServletRequest().setAttribute("BackendHost", ContextHolder.getProperty("app.backend.host"));
		}
		
	}

}
